package com.xj.demoExcel.easyexcel;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.converters.string.StringImageConverter;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;

/**
 * 图片对象--以下是5种形式表示图片
 * 可以设置内容行的高度和宽度,以及表头的高度
 * 也可以单独为每个字段设置宽度
 */
@HeadRowHeight(20)
@ContentRowHeight(100)
@ColumnWidth(30)
public class ImageData {

    @ExcelProperty(index = 0,value = "文件类型")
    private File file;

    @ExcelProperty(index = 1,value = "输入流类型")
    private InputStream inputStream;

    @ExcelProperty(index = 2,value = "字符串类型",converter = StringImageConverter.class)
    private String string;

    @ColumnWidth(80)
    @ExcelProperty(index = 3,value = "字节数组类型")
    private byte[] byteArray;

    /**
     * 当网络延迟较大时,解析会超时报错
     */
    @ExcelIgnore
    @ExcelProperty(index = 4,value = "url类型")
    private URL url;

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public String getString() {
        return string;
    }

    public void setString(String string) {
        this.string = string;
    }

    public byte[] getByteArray() {
        return byteArray;
    }

    public void setByteArray(byte[] byteArray) {
        this.byteArray = byteArray;
    }

    public URL getUrl() {
        return url;
    }

    public void setUrl(URL url) {
        this.url = url;
    }

    @Override
    public String toString() {
        return "ImageData{" +
                "file=" + file +
                ", inputStream=" + inputStream +
                ", string='" + string + '\'' +
                ", byteArray=" + Arrays.toString(byteArray) +
                ", url=" + url +
                '}';
    }
}
